<template>
  <el-dialog
    ref="refAuditDlg"
    title="审核"
    :visible.sync="dialogShow"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :before-close="clearForm"
    width="500px"
    @close="closeDialog"
  >
    <div>
      <el-form ref="refForm" label-width="100px" label="left" :rules="formRules" :model="formData" size="mini">
        <el-row>
          <el-col>
            <el-form-item label="审核结果" prop="resultCode">
              <el-select
                v-model="formData.resultCode"
                placeholder="审核结果"
                style="width:100%"
              >
                <el-option label="同意" :value="1" />
                <el-option label="不同意" :value="0" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :rules="[{ required: !formData.resultCode, message: '意见备注', trigger: 'change' }]" label="意见备注" prop="remarks">
              <el-input v-model="formData.remarks" type="textarea" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer">
      <el-button size="mini" @click="closeDialog">取消</el-button>
      <el-button :loading="saveLoading" size="mini" type="primary" @click="submitForm">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { saveAudit } from '@/api/marketService/dailyPatrol'
export default {
  name: 'AuditDlg',
  components: { },
  props: {
    visible: {
      type: Boolean,
      default: false,
      required: true
    },
    patrolId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      saveLoading: false,
      auditOptions: [], // 审核结果
      formData: {
        id: null,
        resultCode: 1,
        remarks: ''
      },
      formRules: { }

    }
  },

  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  created() {
    this.formData.id = this.patrolId
  },

  methods: {
    closeDialog() {
      this.dialogShow = false
      this.clearForm()
    },
    clearForm(done) {
      this.formData = { }
      this.$refs.refForm && this.$refs.refForm.clearValidate()
      done && done()
    },
    // 提交表单处理
    submitForm() {
      this.$refs['refForm'].validate((valid) => {
        if (valid) {
          this.saveLoading = true
          saveAudit(this.formData).then(res => {
            if (res.success === 1) {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.closeDialog()
              this.$emit('success')
              this.saveLoading = false
            }
          }).catch(() => {
            this.saveLoading = false
          })
        }
      })
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
